﻿/// <reference path="../jquery-3.4.1.min.js" />
/// <reference path="../common.js" />

var editId = null;

$(function () {
    UIInit();
    BindEvents();
    DataInit();
});


function BindEvents() {
    $('#btnCancel').click(function () {
        sysAlert.CloseDialog();
    });

    $('#btnSave').click(SaveInfo);
}

function DataInit() {
    $('#dataArea').bindMutliCodeDropdownList([3,4], function () {
        editId = getUrlParam('id');
        if (!$.isNullOrUndefinedOrEmpty(editId)) {
            LoadEditInfo();
        }
    }, '_none');

}

function UIInit() {
    editId = getUrlParam('id');
    if (!$.isNullOrUndefinedOrEmpty(editId)) {
        $('.editMode').addClass('show');
    }
    else {
        $('.addMode').addClass('show');
    }
}

function LoadEditInfo() {
    $.rajax('handler/userManagement.ashx', { 'rtype': 'GetModelDetail', 'id': editId }, function (retobj) {
        $('#dataArea').bindData(retobj.data);
    });
}

function SaveInfo() {
    var postData = { 'modelInfo': $('#dataArea').getData(), 'rtype': 'SaveModelInfo' }; // $('#dataArea').getData('SaveModelInfo');
    $.rajax('handler/userManagement.ashx', postData, function (retobj) {
        top.sysAlert.success(retobj.msg);
        parent.RefleshMainList();
        sysAlert.CloseDialog();
    });
}